package rsj.api.remind;

import com.rlyy.aibase.utils.base.Box;
import com.rlyy.aibase.utils.base.MapNode;
import common.util.BoxUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import rsj.api.remind.entity.RemindGet;
import rsj.api.remind.entity.RemindInfo;
import rsj.api.remind.entity.RemindLogPage;
import rsj.api.remind.entity.RemindLogTable;
import rsj.service.remind.IRemindService;
import rsj.util.PaginationData;
import common.util.validator.ParameterConversionCheck;

import java.util.List;

/**
 * 账号
 *
 * @author yuanqinglong
 * @since 2021/7/14 13:41
 */
@RestController
public class RemindController {


    @Autowired
    private IRemindService remindService;


    /**
     * 预警日志
     *
     * @param param 参数
     * @return {@link Box}
     */
    @RequestMapping(value = "rsj_remind_log")
    public Box remindLogList(Box param) {
        RemindLogPage remindLogParam = ParameterConversionCheck.parameterConversionCheckFastFail(param, RemindLogPage.class);
        PaginationData<List<RemindLogTable>> paginationData = remindService.remindLogList(remindLogParam);
        return BoxUtil.successBoxToTableData(param,paginationData.getDataList(),paginationData.getTotalCount());
    }

    /**
     * 新增预警配置
     *
     * @param param 参数
     * @return {@link Box}
     */
    @RequestMapping(value = "rsj_remind_add")
    public Box remindAdd(Box param) {
        RemindInfo remindInfo = ParameterConversionCheck.parameterConversionCheckFastFail(param, RemindInfo.class);
        String remindId = remindService.addRemindInfo(remindInfo);
        MapNode responseData = new MapNode().putNode("remind_id", remindId);
        return BoxUtil.successBoxToData(param, "新增成功", responseData);
    }

    /**
     * 根据预警类型查询预警配置
     *
     * @param param 参数
     * @return {@link Box}
     */
    @RequestMapping(value = "rsj_remind_get")
    public Box remindGet(Box param) {
        RemindGet remindInfo = ParameterConversionCheck.parameterConversionCheckFastFail(param, RemindGet.class);
        RemindInfo responseData = remindService.getRemindInfo(remindInfo);
        return BoxUtil.successBoxToData(param,"查询成功", responseData);
    }

    /**
     * 修改预警配置
     *
     * @param param 参数
     * @return {@link Box}
     */
    @RequestMapping(value = "rsj_remind_update")
    public Box remindUpdate(Box param) {
        RemindInfo remindInfo = ParameterConversionCheck.parameterConversionCheckFastFail(param, RemindInfo.class, RemindInfo.Update.class);
        remindService.updateRemindInfo(remindInfo);
        return BoxUtil.successBox(param,"修改成功");
    }

}
